<!-- +----------------------------------------------------------------------
| 麦沃德科技赋能开发者，助力中小企业发展 
+----------------------------------------------------------------------
| Copyright (c) 2017～2024  www.wdadmin.cn    All rights reserved.
+----------------------------------------------------------------------
| 沃德代驾系统并不是自由软件，不加密，并不代表开源，未经许可不可自由转售和商用
+----------------------------------------------------------------------
| Author: MY WORLD Team <bd@maiwd.cn>   www.wdadmin.cn
+----------------------------------------------------------------------
| 确认开始行程 开发者: 麦沃德科技半夏
+---------------------------------------------------------------------- -->

<template>
	<view class="container" @click="closePage()">
		<view class="container-confirm" @click.stop>
			<view class="confirm-content">
				<text class="content-text">当前未上传车辆图片信息</text>
				<text class="content-text">是否直接开始行程</text>
			</view>
			<view class="confirm-footer">
				<view class="footer-btn" @click="handleUpload()">上传图片</view>
				<view class="footer-btn" :style="{color: themeColor}" @click="handleStart()">开始行程</view>
			</view>
		</view>
	</view>
</template>

<script>
	import { mapState } from "vuex"
	export default {
		data() {
			return {
				// 订单id
				orderId: null,
			}
		},
		computed: {
			...mapState({
				themeColor: state => state.app.themeColor,
			})
		},
		onLoad(option) {
			this.orderId = option.id
		},
		methods: {
			// 关闭页面
			closePage() {
				if (getCurrentPages().length == 1) {
					this.$util.toPage({
						mode: 3,
						path: "/pages/index/index"
					})
				} else {
					uni.navigateBack()
				}
			},
			// 上传图片
			handleUpload() {
				let pages = getCurrentPages()
				let prevPage = pages[pages.length - 2]
				prevPage.$vm.stopRefresh = true
				uni.navigateBack({
					success: () => {
						uni.navigateTo({
							url: `/pages/driver/order/photograph?type=1&id=${this.orderId}`,
							animationType: "fade-in"
						})
					}
				})
			},
			// 开始行程
			handleStart() {
				uni.showLoading({
					title: "加载中",
					mask: true,
				})
				this.$util.request("driver.order.startItinerary", {
					id: this.orderId,
				}).then(res => {
					if (res.code == 1) {
						let pages = getCurrentPages()
						let prevPage = pages[pages.length - 2]
						prevPage.$vm.isLoading = true
						this.closePage()
					} else {
						uni.hideLoading()
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
					}
				}).catch(error => {
					uni.hideLoading()
					console.error('开始行程 ', error)
				})
			},
		},
	}
</script>

<style lang="scss">
	page {
		background: transparent;
	}

	.container {
		width: 100vw;
		height: 100vh;
		display: flex;
		justify-content: center;
		align-items: center;
		background: rgba(0, 0, 0, 0.50);

		.container-confirm {
			width: 544rpx;
			max-width: 92vw;
			border-radius: 16rpx;
			background: #FFF;
			padding-top: 32rpx;

			.confirm-content {
				padding: 32rpx 48rpx 48rpx;
				display: flex;
				flex-direction: column;

				.content-text {
					color: #242629;
					text-align: center;
					font-size: 32rpx;
					font-weight: 600;
					line-height: 44rpx;
					white-space: pre-wrap;
				}
			}

			.confirm-footer {
				border-top: 1px solid #E5E5E5;
				display: flex;

				.footer-btn {
					flex: 1;
					width: 50%;
					padding: 32rpx 20rpx;
					text-align: center;
					font-size: 32rpx;
					font-weight: 600;
					line-height: 48rpx;
					border-left: 1px solid #E5E5E5;

					&:first-child {
						border-left: none;
					}
				}
			}
		}
	}
</style>